package ch.nortgram.countdown_worldcup_2014.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import ch.nortgram.countdown_worldcup_2014.R;

public class SlidingMenuFragment extends ListFragment
	{
	View menu_view;
	Fragment newContent;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
		return inflater.inflate(R.layout.menu_list, null);
	    }
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState)
		{
		super.onActivityCreated(savedInstanceState);
		
		String[] values = new String[]
			{
			"Countdown",
			"News",
			"Teams",
			"Feature",
			"Settings",
			"About"
			};
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, values);
        getListView().addFooterView(getActivity().getLayoutInflater().inflate(R.layout.menu_footer,null),null, false);
		setListAdapter(adapter);
	    }
	
	@Override
	public void onListItemClick(ListView lv, View v, int position, long id)
		{
		Fragment newContent = null;
		switch (position)
			{
			case 0:
				newContent = new CountdownFragment();
			break;
			case 1:
				newContent = new NewsFragment();
			break;
			case 2:
				newContent = new TeamFragment();
			break;
			case 3:
				newContent = new RequestFragment();
			break;
			case 4:
				//newContent = new SettingsFragment();
			break;
			case 5:
				newContent = new AboutFragment();
			break;
			}
		if (newContent != null)
			{
			switchFragment(newContent);
			}
		}
	
	// the meat of switching the above fragment
	private void switchFragment(Fragment fragment)
		{
		if (getActivity() == null)
			{
        	return;
        	}
        
        if (getActivity() instanceof FragmentChangeActivity)
        	{
            FragmentChangeActivity fca = (FragmentChangeActivity) getActivity();
            fca.switchContent(fragment);
        	}
		}
	} 